<!DOCTYPE html>
<html>
<head>
    <title>Capacitor Circuit Diagram</title>
</head>
<body>
<canvas id="circuitCanvas" width="450" height="400" style="border:1px solid #d3d3d3;"></canvas>
<script>
    const canvas = document.getElementById('circuitCanvas');
    const ctx = canvas.getContext('2d');

    // Style settings
    ctx.lineWidth = 1.5;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    
    // --- Coordinates ---
    const xA = 80, yA = 80;
    const xB = 80, yB = 320;
    
    const xC1 = 160;
    const xC2 = 300;
    const xC3 = (xC1 + xC2) / 2; // 230
    
    const yTop = yA;
    const yC1_C2 = 140;
    const yMid = 200;
    const yC3 = 250;
    const yBot = yB;

    const capWidth = 50;
    const capGap = 12;

    // --- Draw Wires ---
    ctx.beginPath();
    // Top section
    ctx.moveTo(xA, yTop);                 // From A
    ctx.lineTo(xC2, yTop);                // To C2 top junction
    ctx.moveTo(xC1, yTop);                // From C1 top junction
    ctx.lineTo(xC1, yC1_C2 - capGap / 2); // To C1 top plate
    ctx.moveTo(xC2, yTop);                // From C2 top junction
    ctx.lineTo(xC2, yC1_C2 - capGap / 2); // To C2 top plate

    // Middle section
    ctx.moveTo(xC1, yC1_C2 + capGap / 2); // From C1 bottom plate
    ctx.lineTo(xC1, yMid);                // To mid-junction
    ctx.lineTo(xC2, yMid);                // Horizontal connector
    ctx.moveTo(xC2, yC1_C2 + capGap / 2); // From C2 bottom plate
    ctx.lineTo(xC2, yMid);                // To mid-junction
    ctx.moveTo(xC3, yMid);                // From mid-point
    ctx.lineTo(xC3, yC3 - capGap / 2);    // To C3 top plate

    // Bottom section
    ctx.moveTo(xC3, yC3 + capGap / 2);    // From C3 bottom plate
    ctx.lineTo(xC3, yBot);                // To bottom wire
    ctx.lineTo(xB, yBot);                 // To B

    ctx.stroke();

    // --- Draw Terminals ---
    ctx.beginPath();
    ctx.arc(xA, yA, 7, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.beginPath();
    ctx.arc(xB, yB, 7, 0, 2 * Math.PI);
    ctx.stroke();

    // --- Draw Capacitors ---
    function drawCapacitor(x, y, width, gap) {
        ctx.beginPath();
        ctx.moveTo(x - width / 2, y - gap / 2);
        ctx.lineTo(x + width / 2, y - gap / 2);
        ctx.moveTo(x - width / 2, y + gap / 2);
        ctx.lineTo(x + width / 2, y + gap / 2);
        ctx.stroke();
    }
    drawCapacitor(xC1, yC1_C2, capWidth, capGap);
    drawCapacitor(xC2, yC1_C2, capWidth, capGap);
    drawCapacitor(xC3, yC3, capWidth, capGap);
    
    // --- Draw Labels ---
    // A and B labels
    ctx.font = '24px "Times New Roman"';
    ctx.fillText('A', xA - 30, yA + 8);
    ctx.fillText('B', xB - 30, yB + 8);

    // Capacitor labels with subscripts
    function drawSubscriptText(baseText, subText, x, y) {
        ctx.font = 'italic 24px "Times New Roman"';
        const baseWidth = ctx.measureText(baseText).width;
        ctx.fillText(baseText, x, y);
        
        ctx.font = 'italic 16px "Times New Roman"';
        ctx.fillText(subText, x + baseWidth - 4, y + 6);
    }
    
    drawSubscriptText('C', '1', xC1 - 55, yC1_C2 + 8);
    drawSubscriptText('C', '2', xC2 + 15, yC1_C2 + 8);
    drawSubscriptText('C', '3', xC3 - 55, yC3 + 8);
    
    // Draw bottom text (Chinese)
    ctx.font = '24px "SimSun"';
    ctx.fillText('习题 7-47 图', 150, 370);
</script>
</body>
</html>